<template>
  <div>
    <FilterTable ref="table" columnsRef="zjfygjprojectTable" :height="200" :columns="columns" :dataSource="list" :onColumnsChange="columns => (this.columns = columns)" :onSyncTableData="syncTableFun">
      <template slot="moreActions">
        <span @click="delRecordHandle">批量删除</span>
      </template>
      <template slot="controls" slot-scope="props">
        <!-- <el-button size="small" type="primary" @click="addRecordHandle(1)">整单派工</el-button>
        <el-button size="small" type="primary" @click="addRecordHandle(2)">派工</el-button>
        <el-button size="small" type="primary" @click="addRecordHandle(3)">打印派工</el-button>-->
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addRecordHandle(4)">新增</el-button>
      </template>
    </FilterTable>
    <Drawer :visible.sync="visible_drawer" title="新增维修项目" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <AddRecordPanel @close="closeDrawerHandle" />
    </Drawer>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import AddRecordPanel from './repairProPanels/addRecordPanel';
import { getroLabourByestimateNOList } from '@/api/repair/repairReception/evaluation/index';
import { getSflbSelect, getSfqfSelect, getWxtypeSelect, getGongzSelect, getSflbList } from '@/api/repair/repairReception/customer';

export default {
  name: 'RepairPro',
  components: {
    AddRecordPanel
  },
  mixins: [dictionary],
  props: ['Tlist', 'code', 'isclear'],
  data() {
    return {
      columns: this.createTableColumns(),
      list: [],
      visible_drawer: false
    };
  },
  watch: {
    dataList(val) {
      this.insertRecords(val);
    },
    Tlist(val) {
      if (val.length > 0) {
        this.list = val;
      }
    },
    isclear(val) {
      if (val) {
        this.list = [];
        this.$emit('changeClear', false);
      }
    }
  },
  created() {
    console.log(this.Tlist, '11111111');
    if (this.Tlist.length > 0) {
      this.list = this.Tlist;
    }
    if (this.isclear) {
      this.list = [];
      this.$emit('changeClear', false);
    }
  },
  mounted() {},
  mounted() {
    this.getSflbSelect();
    this.getSfqfSelect();
    this.getWxtypeSelect();
    this.getGongzSelect();
    // this.getSflbList();
    this.createBaseTable();
    this.insertRecords(this.dataList);
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费类别',
          dataIndex: 'MANAGE_SORT_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '故障原因',
          dataIndex: 'TROUBLE_CAUSE',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'input'
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '项目代码',
          dataIndex: 'LABOUR_CODEF',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '项目名称',
          dataIndex: 'LABOUR_NAME',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number'
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          precision: 0
        },
        {
          title: '标准工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          precision: 0
        },
        {
          title: '索赔工时',
          dataIndex: 'CLAIM_LABOUR',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          precision: 0
        },
        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number'
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number'
        },
        {
          title: '工种',
          dataIndex: 'WORKER_TYPE_CODE',
          minWidth: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '责任技师',
          dataIndex: 'TECHNICIAN',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否派工',
          dataIndex: 'ASSIGN_TAG',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          filterItems: this.createDictList('1278'),
          render: props => {
            return <span>{this.createDictText(props.row.DOWN_TAG, '1278')}</span>;
          }
        },
        {
          title: '是否增项',
          dataIndex: 'IS_ADDITION',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          filterItems: this.createDictList('1278'),
          render: props => {
            return <span>{this.createDictText(props.row.IS_ADDITION, '1278')}</span>;
          }
        },
        {
          title: '是否委外',
          dataIndex: 'CONSIGN_EXTERIOR',
          sorter: true,
          editable: true,
          render: props => {
            let val = props.row.CONSIGN_EXTERIOR === '1' ? true : false;
            return <el-checkbox value={val} onInput={val => (props.row.CONSIGN_EXTERIOR = val ? '1' : '0')}></el-checkbox>;
          }
        },
        {
          title: '是否不修',
          dataIndex: 'NEEDLESS_REPAIR',
          sorter: true,
          editable: true,
          render: props => {
            let val = props.row.NEEDLESS_REPAIR === '1' ? true : false;
            return <el-checkbox value={val} onInput={val => (props.row.NEEDLESS_REPAIR = val ? '1' : '0')}></el-checkbox>;
          }
        },
        {
          title: '不修原因',
          dataIndex: 'REASON',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1251'),
          editable: true,
          editType: 'select',
          editItems: this.createDictList('1251'),
          disabled: true
        },
        {
          title: '是否预拣',
          dataIndex: 'PRE_CHECK',
          sorter: true,
          editable: true,
          render: props => {
            let val = props.row.PRE_CHECK === '1' ? true : false;
            return <el-checkbox value={val} onInput={val => (props.row.PRE_CHECK = val ? '1' : '0')}></el-checkbox>;
          }
        },
        {
          title: '是否内返',
          dataIndex: 'INTER_RETURN',
          sorter: true,
          editable: true,
          render: props => {
            let val = props.row.INTER_RETURN === '1' ? true : false;
            return <el-checkbox value={val} onInput={val => (props.row.INTER_RETURN = val ? '1' : '0')}></el-checkbox>;
          }
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '检查结果',
          dataIndex: 'TROUBLE_DESC',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          minWidth: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'input'
        },
        {
          title: '组合代码',
          dataIndex: 'PACKAGE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '项目车型组',
          dataIndex: 'MODEL_LABOUR_CODE',
          minWidth: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '钣喷面积',
          dataIndex: 'SPRAY_AREA',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '故障部位',
          dataIndex: 'POS_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '故障',
          dataIndex: 'APP_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    delRecordHandle() {
      this.BaseTable.EXECUTE_DELETE();
    },
    addRecordHandle(type) {
      this.visible_drawer = true;
    },
    closeDrawerHandle(val, list) {
      this.insertRecords(list);
      this.$emit('changeList', this.list);
      this.visible_drawer = val;
    },
    createBaseTable() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    },
    // 传给父组件
    syncTableFun(val) {
      if (val && val.length > 0) {
        delete val.dataMark;
        this.$emit('syncTablelist', val);
      } else {
        this.$emit('syncTablelist', []);
      }
      console.log(val, '表格数据');
    },
    insertRecords(list) {
      this.BaseTable.EXECUTE_INSERT(list);
    },
    async getSflbSelect() {
      const res = await getSflbSelect();
      this.columns[1].editItems = this.columns[1].filterItems = res.map(x => ({ value: x.MANAGE_SORT_CODE, text: x.MANAGE_SORT_NAME }));
    },
    async getSfqfSelect() {
      const res = await getSfqfSelect();
      this.columns[2].editItems = this.columns[2].filterItems = res.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
    },
    async getWxtypeSelect() {
      const res = await getWxtypeSelect();
      this.columns[4].editItems = this.columns[4].filterItems = res.map(x => ({ value: x.REPAIR_TYPE_CODE, text: x.REPAIR_TYPE_NAME }));
    },
    async getGongzSelect() {
      const res = await getGongzSelect();
      this.columns[15].editItems = this.columns[15].filterItems = res.map(x => ({ value: x.WORKER_TYPE_CODE, text: x.WORKER_TYPE_NAME }));
    },
    async getSflbList() {
      const res = await getSflbList({ limit: 100, offset: 0 });
      this.columns[1].editItems = this.columns[1].filterItems = res.map(x => ({ value: x.MANAGE_SORT_CODE, text: x.MANAGE_SORT_NAME }));
    },
    async getlist(val) {
      console.log(val, '1111111');
      this.list = await getroLabourByestimateNOList({ code: val });
    }
  }
};
</script>

<style lang="less"></style>
